#ifndef SCENE_H
#define SCENE_H

#include "Entity.h"
#include <vector>

class Scene
{
	protected:
		float halfWidth;
		float halfLength;
		std::string type;
		std::string name;
		Entity * current;
		std::vector<Entity*> entities;
	public:
		Scene(float halfWidth, float halfLength, std::string type, std::string name);
		~Scene();
		bool selectEntity(Entity &entity);
		Entity * getSelectedEntity() { return current; }
		void addEntity(Entity &entity);
		void removeEntity(Entity &entity);
		float getHalfWidth() { return halfWidth; }
		float getHalfLength() { return halfLength; }
		std::string getType() { return type; }
		std::string getName() { return name; }
		std::vector<Entity*> getEntities() { return entities; }
};

Scene::Scene (float halfWidth, float halfLength, std::string type, std::string name)
{ 
	if(halfWidth > 1 || halfWidth <= 0 || 
		halfLength > 1 || halfLength <= 0)
	{
		throw "fail constraint: 0 < halfWidth, halfLength <= 1";
	}
	Scene::halfWidth = halfWidth; 
	Scene::halfLength = halfLength; 
	Scene::type = type; 
	Scene::name = name; 
}

Scene::~Scene()
{ 
	if(!current)
	{
		delete current;
	}
}

bool Scene::selectEntity(Entity &entity)
{
	for(int i = 0; i < entities.size(); i++)
	{
		if((*entities[i]).getType() == entity.getType() &&
			(*entities[i]).getName() == entity.getName())
		{
			current = &entity;
			return true;
		}
	}
	return false;
}

void Scene::addEntity(Entity &entity)
{
	entities.push_back(&entity);
}

void Scene::removeEntity(Entity &entity)
{
	for(int i = 0; i < entities.size(); i++)
	{
		if((*entities[i]).getType() == entity.getType() &&
			(*entities[i]).getName() == entity.getName())
		{
			entities.erase(entities.begin() + i);
			return;
		}
	}
}

#endif